# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an


import sys
from PyQt5.QtWidgets import *
from PyQt5.Qt import *
from  PyQt5.QtGui import *

class Moved(QWidget):
    def __init__(self):
        super(Moved, self).__init__()
        layout = QHBoxLayout()
        self.label = QLabel()
        self.label.setText("滑动我改变颜色")
        layout.addWidget(self.label)

        self.bar = QScrollBar()
        self.bar.setMaximum(255)
        self.bar.sliderMoved.connect(self.UI)
        layout.addWidget(self.bar)

        self.setLayout(layout)

    def UI(self):
        # 实例化调色板
        palette = QPalette()
        # 获滑块滑动的值
        color = QColor(self.bar.value())
        # 设置获取到的颜色值
        palette.setColor(QPalette.Foreground,color)
        # 设置写入值
        self.label.setPalette(palette)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    move = Moved()
    move.show()
    sys.exit(app.exec_())